package com.chaopei.order_mng.controller;

import com.chaopei.order_mng.entity.OrderProductVo;
import com.chaopei.order_mng.service.OrderDetailService;
import com.chaopei.order_mng.service.OrderInfoService;
import com.chaopei.order_mng.service.OrderProductVoService;
import com.chaopei.order_mng.utils.MyJson;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author Corday 天涯
 * @Date 2022/5/11 22:53
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    //完成订单的CURD
    @Resource
    private OrderProductVoService orderProductVoService;

    /**
     * 1.获取前端web应用传过来的jsonArray生成订单库
     * http://localhost:8083/order/vo
     *
     * @param jsonArray
     * @return OrderProductVo
     */
    @RequestMapping("/vo")
    public String getVo(String jsonArray) {
        //在业务处理中完成订单表
        List<OrderProductVo> list = MyJson.jsonToVo(jsonArray);
        //生成订单：添加订单基本表order_info与订单详情表order_detail
        String msg = orderProductVoService.saveOrderInfoAndOrderDetail(list);
        //System.out.println("拿到:"+msg);
        return msg;
    }

    /**
     * @param uid
     * @return
     */
    @RequestMapping("/query")
    public Map<Integer, List<OrderProductVo>> queryOrder(int uid) {
        Map<Integer, List<OrderProductVo>> temp = orderProductVoService.queryOrderProductVo(uid);
        return temp;
    }

}
